<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>物业缴费</title>
    <style>
        body{
            margin: 0;
            background-color: #eee;
        }
        header{
            background-color: white;
            padding: 10px ; 
        }

        .chunk{
            width: 80%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: white;
            margin: 20px auto;
            padding: 10px 15px;
            border-radius: 5px;
        }
        .head-portrait{
            width: 50px;
            height: 50px;
            border-radius: 50%;
        }
        .chunk-left{
            display: flex;
        }
        .name-time{
            /* display: inline-block; */
            margin-left: 5px;
        }
        .name-time div{
            margin: 3px 0;
        }
        .seek{
            width: 97%;
            padding: 5px;
            border: solid 1px rgb(133, 129, 129);
        }
        .chunk-room-left {
            width: 35%;
        }

        .chunk-room-right {
            width: 70%;
            display: flex;
            justify-content: space-between;
            color: rgb(174, 175, 175);
        }
         .confirmBtn {
            width: 100%;
            height: 40px;
            line-height: 40px;
            background-color: #1E90FF;
            text-align: center;
            margin: 30px auto;
            color: white;
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <form  id="form1">
    <main>
        <div class="chunk"  style="margin-top:50px">
            <div class="chunk-room-left">小区</div>
            <div class="chunk-room-right">
                {$userinfo.community_name}
            </div>
        </div>
        <div class="chunk" >
            <div class="chunk-room-left">房屋</div>
            <div class="chunk-room-right">
                {$userinfo.room_address}
            </div>
        </div>
        {volist name="billlist" id="vo"}
        <div class="chunk">
            <div class="chunk-left">
                
                <div class="name-time">
                    <div> <input type="checkbox" name="billid[{$vo.id}]" value="{$vo.id}" onclick="moneysum()"/>{$vo.cost_type}</div>
                </div>
            </div>
                <input type="hidden" value="{$vo.bill_entry_amount}" name="ordermoney[]"/>
            <div>
                ￥<span style="color:red">{$vo.bill_entry_amount}</span>
            </div>
        </div>
        {/volist}
         <input type="hidden" name="point" value="{$roominfo.point}"/>
        {if $roominfo.point>0} 
        <div class="chunk">
            <div class="chunk-left">
                
                <div class="name-time">
                    <div> 可用积分</div>
                </div>
            </div>
            <div>

                {$roominfo.point}&nbsp;&nbsp;&nbsp;<input type="checkbox" name="point_status" value="1"   onclick="moneysum()"/>是否使用积分
            </div>
        </div>
        {/if}
        <div class="chunk">
            <div class="chunk-left">
                
                <div class="name-time">
                    <div>实付金额</div>
                </div>
            </div>
            <div style="color:red">
                ￥<span id="ordermoney">0</span>
            </div>
        </div>
       <div class="chunk" style="background-color: #eee">
            <input type="button" class="confirmBtn" value="确认缴费"    style="margin:0 auto;" onclick="createOrder()"/>
        </div>
    </main>
    </form>
</body>
</html>
<script src="static/index/js/jquery.js"></script>
<script type="text/javascript">
    function createOrder(){
         var form = new FormData(document.getElementById("form1"));
          $.ajax({
                url:"{:url('createOrder')}",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                success:function(r){
                    
                    if (r.order_no) {
                        tradePay(r.order_no)
                    }else{
                        alert(r.info)
                        location.reload()  
                    }
                },
                error:function(e){
                    alert("错误！！");
                    
                }
        });            
    }

    function moneysum(){
        var form = new FormData(document.getElementById("form1"));
          $.ajax({
                url:"{:url('moneysum')}",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                success:function(r){
                
                    if (r.state=="1") {
                        document.getElementById('ordermoney').innerHTML=r.info
                    }else{
                        alert(r.info);
                        location.reload()  
                    }
                },
                error:function(e){
                    alert("错误！！");
                    
                }
        });    
    }

        // 由于js的载入是异步的，所以可以通过该方法，当AlipayJSBridgeReady事件发生后，再执行callback方法
    function ready(callback) {
         if (window.AlipayJSBridge) {
             callback && callback();
         } else {
             document.addEventListener('AlipayJSBridgeReady', callback, false);
         }
    }

    function tradePay(tradeNO) {
        ready(function(){
             // 通过传入交易号唤起快捷调用方式(注意tradeNO大小写严格)
             AlipayJSBridge.call("tradePay", {
                  tradeNO: tradeNO
             }, function (data) {
                 if ("9000" == data.resultCode) {
                     
                     window.location.href='http://p.alipay.com/P/ZnbM272z';
                 }
             });
        });
    }
</script>